package com.lce.service.impl;

import com.lce.beans.Attendance;
import com.lce.beans.Leave;
import com.lce.beans.TimeTable;
import com.lce.beans.User;
import com.lce.beans.UserUid;
import com.lce.dao.AttendanceDao;
import com.lce.dao.DictDao;
import com.lce.dao.TimeTableDao;
import com.lce.dao.UserDao;
import com.lce.service.UserSigin;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;


@Service
public class UserSiginImpl implements UserSigin {

    private SqlSessionTemplate sqlSessionTemplate;

    //setSqlSessionTemplate模板
    @Autowired
    public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
        this.sqlSessionTemplate = sqlSessionTemplate;
    }


    @Override
    public TimeTable getTimeTable(int a) {
        TimeTableDao timeTableDao=sqlSessionTemplate.getMapper(TimeTableDao.class);
        TimeTable timeTable = timeTableDao.getTimeTable(a);
        return timeTable;
    }

    @Override
    public String getResult(int result) {
        DictDao dictDao = sqlSessionTemplate.getMapper(DictDao.class);
        String result1 = dictDao.getResult(result);
        return  result1;
    }

    @Override
    public int getAttendance(Map map) {
        AttendanceDao attendanceDao = sqlSessionTemplate.getMapper(AttendanceDao.class);
        int i = attendanceDao.getAttendance(map);
        return i;
    }

    @Override
    public void addAttendance(Map map) {
        AttendanceDao attendanceDao = sqlSessionTemplate.getMapper(AttendanceDao.class);
        attendanceDao.addAttendance(map);
    }

    @Override
    public void updateAttendance(Map map) {
        AttendanceDao attendanceDao = sqlSessionTemplate.getMapper(AttendanceDao.class);
        attendanceDao.updateAttendance(map);
    }

    @Override
    public List<Attendance> getRecord(int uid) {
        AttendanceDao attendanceDao = sqlSessionTemplate.getMapper(AttendanceDao.class);
        List<Attendance> attendances=attendanceDao.getRecord(uid);


        return attendances;
    }

    @Override
    public List<Leave> getLeave(int uid) {
        AttendanceDao attendanceDao = sqlSessionTemplate.getMapper(AttendanceDao.class);
        List<Leave> leaves=attendanceDao.getLeave(uid);
        return leaves;
    }

    @Override
    public int getToday(String format) {
        DictDao dictDao = sqlSessionTemplate.getMapper(DictDao.class);
        int a=dictDao.getToday(format);
        return a;
    }

    @Override
    public void addAllRecord(List<UserUid> userList) {
        System.out.println(userList);
        DictDao dictDao = sqlSessionTemplate.getMapper(DictDao.class);
        dictDao.addAllRecord(userList);
        System.out.println("zhequamshi16????"+userList);
    }

    @Override
    public int getBack(Map map1) {
            AttendanceDao attendanceDao = sqlSessionTemplate.getMapper(AttendanceDao.class);
            int i = attendanceDao.getBack(map1);
            return i;

    }
}
